package com.example.myson;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.WindowManager;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


/**
 * Created by Administrator on 2017/3/6 0006.
 */

public class Urlhttp {
    public static String getUrl(String path) throws IOException {
        String json = null;
        URL url = new URL(path);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        InputStream in=conn.getInputStream();
        BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(in));
        json =bufferedReader.readLine();
        bufferedReader.close();
        return json;
    }

    public static void getString(final String path, final Handler handler) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    URL url=new URL(path);
                    String a="";
                    HttpURLConnection conn= (HttpURLConnection) url.openConnection();
                    Log.d("aaa","1");
                    conn.setConnectTimeout(2000);
                    conn.setRequestMethod("GET");
                    Log.d("aaa","3");
                    InputStream in=conn.getInputStream();
                    Log.d("aaa","2");
                    BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(in));
                    a=bufferedReader.readLine();
                    Message aaa=handler.obtainMessage();
                    aaa.obj=a;
                    handler.sendMessage(aaa);
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();

    }

    public static String gettime(){
        SimpleDateFormat formatter=new SimpleDateFormat("HH:mm");
        Date curDate=new Date(System.currentTimeMillis());
        String str=formatter.format(curDate);
        return str;
    }
    public static String getdata(){
        SimpleDateFormat formatter    =   new    SimpleDateFormat    ("yyyy年MM月dd日    HH:mm:ss     ");
        Date curDate    =   new    Date(System.currentTimeMillis());
        String    str    =    formatter.format(curDate);
        return str;
        //获取当前时间

//        Calendar c = Calendar.getInstance();
//        mCurrentDay = c.get(Calendar.DAY_OF_MONTH) ;
//        c.set(Calendar.DAY_OF_MONTH,mDay+3);
//        mDay = c.get(Calendar.DAY_OF_MONTH);
//        Calendar c = Calendar.getInstance();
//        取得系统日期:year = c.get(Calendar.YEAR)
//        month = c.grt(Calendar.MONTH)
//        day = c.get(Calendar.DAY_OF_MONTH)
//        取得系统时间：hour = c.get(Calendar.HOUR_OF_DAY);
//        minute = c.get(Calendar.MINUTE)

        //Calendar c = Calendar.getInstance();
        //String  aaa="nian"+c.get(Calendar.YEAR)+"yue"+c.get(Calendar.MONTH)+"ri"+c.get(Calendar.DAY_OF_MONTH);  少个月
    }
    public static String getnextdate(int i){
        SimpleDateFormat sDateFormat    =   new    SimpleDateFormat("yyyyMMdd");
        //String date=sDateFormat.format(new java.util.Date());
        Calendar c = Calendar.getInstance();
        //System.out.println("当前日期:"+sDateFormat.format(c.getTime()));
        c.add(Calendar.DAY_OF_MONTH, i);
        //System.out.println("增加一天后日期:"+sDateFormat.format(c.getTime()));

        return sDateFormat.format(c.getTime());
    }
    public static void transparentStatusBar(Activity activity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
        } else {
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }//透明状态栏
}
